#ifndef device_h
#define device_h

#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>

#include "message.h"

#include "log.h"

struct message;

typedef struct {
	char *file_name;
	int file_descriptor;
	char *device_name;
	pthread_t input_thread;
	pthread_t output_thread;
	struct message *(*read)(void *device);
	int32_t (*write)(void *device, const struct message *message);
} device;
typedef device _device;

#define device_flag_input (1 << 0)
#define device_flag_output (1 << 1)
#define pthread_t_no_thread ((pthread_t) - 1)
#define pthread_t_allow_thread ((pthread_t) - 2)

device *device_create(const char *file_name, const char *device_name,
					  struct message *(*read)(void *device),
					  int32_t (*write)(void *device,
									   const struct message *message));
int32_t device_start(device *device, uint32_t flag);
int32_t device_stop(device *device, uint32_t flag);
device *device_destory(device *device);

#endif